package com.jiutong.meipengdai.ui.activitys;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.jiutong.meipengdai.R;
import com.jiutong.meipengdai.base.BaseActivity;
import com.jiutong.meipengdai.entity.HouseDetailBean;
import com.jiutong.meipengdai.http.present.CommonPresent;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;
import com.jiutong.meipengdai.utils.NumUilt;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by suxi on 2017/6/1.
 */

public class HouseDetailActivity extends BaseActivity {

    @Bind(R.id.tv_house_price)
    TextView tvHousePrice;  //可贷额度
    @Bind(R.id.tv_youquanren)
    TextView tvYouquanren; //权利人
    @Bind(R.id.tv_house_card)
    TextView tvHouseCard;  //房产证
    @Bind(R.id.tv_xiaoqu)
    TextView tvXiaoqu;  //小区
    @Bind(R.id.id_house_area)
    TextView tvHouseArea; //房屋面积
    @Bind(R.id.id_inner_area)
    TextView tvInnerArea; //套内建筑面积
    @Bind(R.id.tv_total_level)
    TextView tvTotalLevel; //总楼层
    @Bind(R.id.tv_building_num)
    TextView tvBuildingNum; //楼栋号
    @Bind(R.id.tv_room_num)
    TextView tvRoomNum; //门牌号
    //    @Bind(R.id.tv_register_time)
//    TextView tvRegisterTime; //注册时间
    @Bind(R.id.tv_house_type)
    TextView tvHouseType; // 房屋类型
    @Bind(R.id.tv_propert)
    TextView tvPropert; // 房屋性质
    @Bind(R.id.tv_condition)
    TextView tvCondition; //使用状况
    @Bind(R.id.tv_state_house)
    TextView tvStateHouse; //房产状态
    @Bind(R.id.tv_diya_start_time)
    TextView tvDiyaStartTime; //抵押起始时间
    @Bind(R.id.tv_diya_end_time)
    TextView tvDiyaEndTime;//抵押结束时间
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_unit)
    TextView tvUnit;
    @Bind(R.id.tv_no_date)
    TextView tvNoDate;
    private String houseId;

    @Override
    public int getLayoutResouceId() {
        return R.layout.activity_house_detail;
    }

    @Override
    protected void initDate(Bundle savedInstanceState) {
        super.initDate(savedInstanceState);

        Bundle extras = getIntent().getExtras();
        houseId = extras.getString("houseId");
    }


    @Override
    protected void initView() {
        super.initView();
        ButterKnife.bind(this);

        tvTitle.setText("房产详情");

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("houseId", houseId);

        CommonPresent.getHouseDetial(mContext, new SubscriberOnNextListener<HouseDetailBean>() {
            @Override
            public void onNext(HouseDetailBean result) {

                if (!"200".equals(result.getResCode()))
                    return;

                tvNoDate.setVisibility(View.GONE);
                HouseDetailBean.DataBean.HouseLoanBean houseDetail = result.getData().getHouseLoan();

                String fainalAssAmount = houseDetail.getFainalAssAmount();
                float price = Float.parseFloat(fainalAssAmount);
                if (price >= 10000) {

                    tvHousePrice.setText(NumUilt.formatFloat(price / 10000) + "");  //可贷额度
                    tvUnit.setVisibility(View.VISIBLE);
                } else {
                    tvUnit.setVisibility(View.GONE);
                    tvHousePrice.setText(NumUilt.formatFloat(price) + "");  //可贷额度
                }
                tvYouquanren.setText(houseDetail.getRealName()); //权利人
//                tvIdNum.setText(houseDetail.getCardNumber());   //身份证
                tvHouseCard.setText(houseDetail.getHouseCard());  //房产证
                tvXiaoqu.setText(houseDetail.getResidentialArea());  //小区
                tvTotalLevel.setText(houseDetail.getTotalFloor());
                tvBuildingNum.setText(houseDetail.getBuildingNumber());
                tvRoomNum.setText(houseDetail.getRoomNumber());
                tvInnerArea.setText(houseDetail.getInnerBuildingArea() + "㎡");
//                tvRegisterTime.setText(housetail.get);
//                tvHouseAddress.setText(houseDetail.getHouseProvince() + houseDetail.getHouseCity() + houseDetail.getHouseStreet() + houseDetail.getResidentialArea()); // 房屋地址
                tvHouseArea.setText(houseDetail.getHouseSize() + "㎡"); //房屋面积
                tvHouseType.setText(houseDetail.getHouseTypeDesc()); // 房屋类型
                tvPropert.setText(houseDetail.getHouseStatusDesc()); // 房屋性质
                tvCondition.setText("1".equals(houseDetail.getIsOnlyHave()) ? "共同应有" : "单独拥有          "); //使用状况 共有状况  是否独有
//                tvHouseAge.setText(houseDetail.getHosueAge() + "年"); //房龄
//                tvZongdiNo.setText(houseDetail.getLandNo()); //宗地号
//                tvZongdiArea.setText(houseDetail.getLandSize() + " ㎡"); //宗地面积

                if ("0".equals(houseDetail.getMortgageStatus())) {
                    tvStateHouse.setText("预抵押"); //房产状态 0：预抵押，1：申请中，2：正在抵押，3：抵押结束

                } else if ("1".equals(houseDetail.getMortgageStatus())) {
                    tvStateHouse.setText("房产审核中"); //房产状态 0：预抵押，1：申请中，2：正在抵押，3：抵押结束

                } else if ("2".equals(houseDetail.getMortgageStatus())) {
                    tvStateHouse.setText("抵押中"); //房产状态 0：预抵押，1：申请中，2：正在抵押，3：抵押结束

                } else if ("3".equals(houseDetail.getMortgageStatus())) {
                    tvStateHouse.setText("抵押结束"); //房产状态 0：预抵押，1：申请中，2：正在抵押，3：抵押结束

                }
                tvDiyaStartTime.setText(houseDetail.getStartDate()); //抵押起始时间
                tvDiyaEndTime.setText(houseDetail.getEndDate());//抵押结束时间
            }

            @Override
            public void onError(Throwable e) {

            }
        }, hashMap);
    }

    @OnClick({R.id.rl_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

}
